package org.linlinjava.litemall.core.notify;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.*;
import org.linlinjava.litemall.core.util.yml_config;
import org.springframework.beans.factory.annotation.Autowired;

//阿里短信
public class almsg {

    @Autowired
    private yml_config ymlconfig;

    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId("LTAI5tJK1SUQMni1kLiU25go")
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret("XwVdRV3IqXzPVuy6fnirlXNnltkGBL");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    //发送短信
    public SendSmsResponse sendMsg(String code) throws Exception {
        com.aliyun.dysmsapi20170525.Client client = createClient(null,null);
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers("17512962910")
                .setTemplateParam("{\"code\":\""+code+"\"}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        SendSmsResponse response=new SendSmsResponse();
        try {
            // 复制代码运行请自行打印 API 的返回值
            response = client.sendSmsWithOptions(sendSmsRequest, runtime);
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return response;
    }


}
